package com.freewater.javabase.demo.nio;

import java.nio.file.Path;
import java.nio.file.Paths;

public class PathsDemo {
    public static void main(String[] args) {
        // 获取路径
        Path path = Paths.get("mydir");
        System.out.println(path.toAbsolutePath());

        path = Paths.get(".");
        System.out.println(path.toAbsolutePath());

        path = Paths.get("..");
        System.out.println(path.toAbsolutePath());

        // 相对路径
        Path basePath = Paths.get("/data");
        path     = Paths.get("/data/subdata/subsubdata/myfile.txt");
        System.out.println(basePath.relativize(path));
        System.out.println(path.relativize(basePath));

        // normalize
        path = Paths.get("/data/subdata/subsubdata/../myfile.txt");
        System.out.println(path.normalize());
    }
}
